﻿<!DOCTYPE html>
<html>
<head>
    <!--<base href="../" />-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="/static/css/angularStyle.css" />
    <link rel="stylesheet" href="/static/css/common/reset.css" />
    <link rel="stylesheet" href="/static/css/associate.css" />
    <link rel="stylesheet" href="/static/css/sweetalert.min.css" />
    <title>宾果高校</title>
</head>
<body>
    <div class="supportDetail" ng-app="myApp">
        <div id="divHeader"></div>
        <section class="main pt10">
            <ul class="support-ul pt10 clearfix">
                <li>首页</li>
                <li>社团</li>
                <li>赞助筹备</li>
                <li>我的赞助</li>
                <li>详情查看</li>
            </ul>
        </section>
        <section class="main" ng-controller="projectDetailCtrl" ng-cloak>
            <div class="support-activity" ng-model="names">
                <h1 class="f20 textcenter">{{names.ProjectName}}</h1>
                <h2 class="textcenter mt10">{{names.CreateDate | date:'yyyy-MM-dd HH:mm:ss'}}      <!--<span class="colorRed">200</span>人已浏览--></h2>
                <h3 class="support-act-title f16 mb10">活动简介</h3>
                <article class="line2">
                    <p ng-bind-html="names.Introduction | to_trusted"></p>
                </article>
                <a id="btnEdit" ng-if="names.CanEdit =='true' " tag="{{names.CanEdit}}" href="/release.html?id={{names.ProjectID}}" class="support-act-editBtn">编辑赞助书</a>
                <a id="btnEditAfterDelete" ng-if="names.CanDeleteContract =='true' " tag="{{names.ProjectID}}" onclick="UpdateAfterDelete(this); return false;" href="javascript:void(0);" class="support-act-editBtn">编辑赞助书</a>
                <a ng-if="names.CanEdit =='false' && names.CanDeleteContract =='false'" href="/release-detail.html?id={{names.ProjectID}}" class="support-act-editBtn">查看活动详情</a>
            </div>
        </section>
        <section class="main">
            <h2 class="f16 mb10">
                邀请状态:
                <select id="selectStatus">
                    <option value="Confirmed">未确定</option>
                    <option value="Effective">已同意</option>
                    <option value="Rejected">已拒绝</option>
                    <option value="Overdue">已过期</option>
                </select>
            </h2>
            <ul class="support-list" ng-controller="contractDetailCtrl" ng-cloak>
                <li class="clearfix" ng-repeat="x in names">
                    <div class="support-list-left fl">
                        <div class="support-lleft-top clearfix">
                            <p class="fl"><label id="lblName">赞助企业</label> ：{{x.Name}}</p>
                            <p class="fr">{{x.CreateDate | date:'yyyy-MM-dd HH:mm:ss'}}</p>
                        </div>
                        <div class="support-lleft-bottom">
                            <label class="veraT f16 colorRed"><label id="lblSup">活动要求</label>：</label>
                            <p style="border: 1px solid; height: 110px; overflow-y: scroll" ng-bind-html="x.Feedback | to_trusted"></p>
                        </div>
                    </div>
                    <div class="support-list-right fr">
                        <div class="support-lright-top">
                            <p class="support-lrtop-money"><label id="lblAmount">提供赞助金</label>：<label class="colorLGray f24">¥</label><span>{{x.Amount}}</span></p>
                            <div class="clearfix">
                                <div class="support-lrtop-text fl">
                                    <p><label id="lblContractorName">企业联系人</label>:<span>{{x.ContractorName}}</span></p>
                                    <p><label>联系电话:</label><span>{{x.ContractorPhone}}</span></p>
                                    <p><label>QQ:</label><span>{{x.ContractorQQ}}</span></p>
                                </div>
                                <div class="support-lrtop-text fr">
                                    <div id="divAgent">
                                        <p><label>代理官:</label><span>{{x.AgentName}}</span></p>
                                        <p><label>联系电话:</label><span>{{x.AgentPhone}}</span></p>
                                        <p><label>QQ:</label><span>{{x.AgentQQ}}</span></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="support-lright-bottom">
                            <a href="javascript:void(0);" tag="{{x.ContractID}}" onclick="Update(this, 'Effective')" ng-if="x.Status == 'Confirmed' && x.SubStatus == 'Pending'" class="support-lrbottom-btn agree w50 fl">确认合作</a>
                            <a href="javascript:void(0);" tag="{{x.ContractID}}" onclick="Update(this, 'Effective')" ng-if="x.CreatorType == 'Student' && x.Status == 'Confirmed' && x.SubStatus == 'SponMoneyChanged'" class="support-lrbottom-btn agree w50 fl">同意修改后的金额</a>
                            <a href="javascript:void(0);" tag="{{x.ContractID}}" onclick="Update(this, 'Rejected')" ng-if="x.Status == 'Confirmed'" class="support-lrbottom-btn refuse w50 fl">拒绝，希望下次合作</a>
                            <a href="javascript:void(0);" ng-if="x.CreatorType == 'Company' && x.Status == 'Confirmed' && x.SubStatus == 'SponMoneyChanged'" class="support-lrbottom-btn btop agree w50 fl">等待确认中</a>
                            <a href="javascript:void(0);" tag="{{x.ContractID}}" ng-if="x.CreatorType == 'Company' && x.Status == 'Confirmed' && (x.SubStatus == 'Pending' || x.SubStatus == 'SponMoneyChanged')" onclick="ShowUpdate(this);" class="support-lrbottom-btn edit w100 fl">修改提供赞助金</a>
                            <a href="javascript:void(0);" ng-if="x.Status == 'Effective'" class="support-lrbottom-btn agree w100 fl">已经同意，并生成合同</a>
                            <a href="javascript:void(0);" ng-if="x.Status == 'Rejected'" class="support-lrbottom-btn refuse w100 fl">已拒绝</a>
                            <a href="javascript:void(0);" ng-if="x.Status == 'Overdue'" class="support-lrbottom-btn refuse w100 fl">已过期</a>
                        </div>
                    </div>
                </li>
            </ul>
        </section>
        <div id="divFooter"></div>
    </div>
    <div class="mask hide"></div>
    <!--提交反馈意见-->
    <div class="popBox contractBox hide" id="supportEditBox">
        <h1 class="contractBox-title">修改赞助金<a href="javascript:void(0)" class="contractBox-title-close"></a></h1>
        <div class="contractBox-content">
            <p class="contractBox-content-url">
                <label>提供赞助金：</label>
                <input type="text" id="txtAmount" placeholder="请输入修改金额" />
            </p>
            <div class="clearfix">
                <a href="javascript:void(0)" class="up-hb-submit cancel">取消</a>
                <a href="javascript:void(0)" onclick="UpdateAmount(this)" class="up-hb-submit confirm">确认修改</a>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript" src="/static/js/ref/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/static/js/self/common.js"></script>
<script type="text/javascript" src="/static/js/ref/angular.min.js"></script>
<script type="text/javascript" src="/static/js/ref/sweetalert.min.js"></script>
<script>

    var param = common.getUrlArgStr();
    if (!common.checkValue(param.id))
        window.location = "support.html";

    $("#divHeader").load("/wuc/header.html");
    $("#divFooter").load("/wuc/footer.html");

    var userType = common.GetUserType();

    if (!common.checkValue(userType))
        window.location = "/index.html";

    if (userType == 1) {
        $("#lblName").html("筹备社团");
        $("#lblSup").html("社团承诺");
        $("#lblAmount").html("所需赞助金");
        $("#lblContractorName").html("社团联系人");
        $("#divAgent").hide();
    }

    function AfterCompleted(ctx) {
        if (ctx == null) {
            common.alertMessage("无数据.");
            return;
        }

        var ele = document.querySelector("[ng-controller=contractDetailCtrl]");

        angular.element(ele).scope().update(ctx.ResponseList);
    }

    function AfterUpdated(ctx) {
        if (ctx == null) {
            common.alertMessage("无数据.");
            return;
        }

        common.commonAjax({ type: 'Get', url: '/api/project/ListContract?id=' + param.id + '&status=Confirmed', sMethod: AfterCompleted });
        $(".mask,#supportEditBox,cancel").hide();
    }

    function Update(obj, type) {

        var values = {};
        values.ContractID = $(obj).attr("tag");
        values.Status = type;

        common.commonAjax({ type: 'Post', url: '/api/project/UpdateContractStatus', data: values, sMethod: AfterUpdated, alert: true });
    }

    function AfterCancelled(ctx) {
        if (ctx == null) {
            common.alertMessage("无数据.");
            return;
        }

        window.location = "/release.html?id=" + projectID;
    }

    var projectID;

    function UpdateAfterDelete(obj) {

        var msg = userType == 2 ? "是否要删除所有企业未确定邀请后编辑赞助书" : "是否要删除所有社团未确定邀请后编辑赞助书";

        var question = confirm(msg);
        if (question) {
            var values = {};
            projectID = values.ProjectID = $(obj).attr("tag");
            common.commonAjax({ type: 'Post', url: '/api/project/CancelContractStatusByProject', data: values, sMethod: AfterCancelled, alert: true });
        }
    }

    var myApp = angular.module('myApp', []);

    common.CreateController({ name: 'projectDetailCtrl', url: '/api/project/get?id=' + param.id, objType: 'dict', htmlFilter: true, app: myApp });
    common.CreateController({ name: 'contractDetailCtrl', app: myApp, htmlFilter: true });
    common.commonAjax({ type: 'Get', url: '/api/project/ListContract?id=' + param.id + '&status=Confirmed', sMethod: AfterCompleted });

    $("#selectStatus").change(function () {

        //var canEdit = $("#btnEdit").attr("tag");
        //if (canEdit == "false")
        common.commonAjax({ type: 'Get', url: '/api/project/ListContract?id=' + param.id + '&status=' + $(this).val(), sMethod: AfterCompleted });
    })

    function UpdateAmount(obj) {

        var values = {};
        values.ID = contractID;
        values.Amount = $("#txtAmount").val();

        common.commonAjax({ type: 'Post', url: '/api/project/UpdateContractAmount', data: values, sMethod: AfterUpdated, alert: true });
    }

    var contractID;

    function ShowUpdate(obj) {
        contractID = $(obj).attr("tag");
        $(".mask,#supportEditBox").show();
        e.stopPropagation();
    }

    $(".contractBox-title-close, .up-hb-submit.cancel").on('click', function (e) {
        $(".mask,#supportEditBox,cancel").hide();
        e.stopPropagation();
    })

</script>
